package _Pan3D.particle
{
	import _Pan3D.particle.interfaces.IParticle;

	public class ParticleCombine
	{
		private var _x:Number = 0;
		private var _y:Number = 0;
		private var _z:Number = 0;
		private var particleAry:Vector.<IParticle>;
		private var _time:Number = 0;
		public function ParticleCombine()
		{
			particleAry = new Vector.<IParticle>;
		}
		
		public function addParticle(value:IParticle):void{
			particleAry.push(value);
			value.callFun = removeParticle;
			value.parent = this;
		}
		
		public function removeParticle(value:IParticle):void{
			/*
			var index:int = particleAry.indexOf(value);
			if(index >= 0){
				particleAry.splice(index,1);
			}
			*/
			for each(var particel:IParticle in particleAry){
				if(!particel.end){
					return;
				}
			}
			playEnd();
		}
		
		public function update(ts:Number):void{
			_time += ts;
			for each(var particel:IParticle in particleAry){
				if(!particel.end && particel.beginTime < _time)
					particel.update(ts);
			}
		}

		public function get x():Number
		{
			return _x;
		}

		public function set x(value:Number):void
		{
			_x = value;
			updataPos();
		}

		public function get y():Number
		{
			return _y;
		}

		public function set y(value:Number):void
		{
			_y = value;
			updataPos();
		}

		public function get z():Number
		{
			return _z;
		}

		public function set z(value:Number):void
		{
			_z = value;
			updataPos();
		}
		
		public function updataPos():void{
			for each(var particel:IParticle in particleAry){
				particel.updataPos();
			}
		}
		
		public function playEnd():void{
			reset();
		}
		
		public function reset():void{
			for each(var particel:IParticle in particleAry){
				particel.reset();
			}
		}
		
		
	}
}